package com.dream.cgomall.service.impl;

import com.dream.cgomall.dao.CgoAdminAttentionDao;
import com.dream.cgomall.dao.CgoAdminHistoryDao;
import com.dream.cgomall.dao.CgoAdminMylikeDao;
import com.dream.cgomall.dto.*;

import com.dream.cgomall.entity.CgoAdminHistory;
import com.dream.cgomall.entity.CgoDiscover;
import com.dream.cgomall.service.CgoAdminGoodsService;
import com.dream.cgomall.service.ServiceResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CgoAdminGoodsServiceImpl implements CgoAdminGoodsService {
    @Autowired(required = false)
    CgoAdminHistoryDao cgoAdminHistoryDao;
    @Autowired(required = false)
    CgoAdminAttentionDao cgoAdminAttentionDao;
    @Autowired(required = false)
    CgoAdminMylikeDao cgoAdminMylikeDao;

    //获取用户历史记录
    public ServiceResult<List<CgoAdminHistory>> getHistoryGoods(Integer userId){
        return  ServiceResult.of(cgoAdminHistoryDao.selectGoods(userId));
    }
    //获取用户收藏文章
    @Override
    public ServiceResult<List<CgoDiscover>> getMyLikeGoods(Integer userId) {
        List<CgoDiscover> goodDTOList=cgoAdminMylikeDao.selectGoodsByUserId(userId);
        return ServiceResult.of(goodDTOList);
    }
    //获取用户关注商品
    @Override
    public ServiceResult<List<GoodDTO>> getAttention(Integer userId) {
        List<GoodDTO> goodDTOList=cgoAdminAttentionDao.selectGoodsByUserId(userId);
        return ServiceResult.of(goodDTOList);
    }


    @Override
    public ServiceResult NotMylike(List idList) {
        try {
            if(idList!=null){
                cgoAdminMylikeDao.deleteById(idList);
                return ServiceResult.success();
            }else{
                return ServiceResult.badResult(null);
            }
        }catch (RuntimeException e){
            return ServiceResult.badResult(null);
        }
    }

    @Override
    public ServiceResult NotHistory(List idList) {
        try {
            if(idList!=null){
                cgoAdminHistoryDao.deleteById(idList);
                return ServiceResult.success();
            }else{
                return ServiceResult.badResult(null);
            }
        }catch (RuntimeException e){
            return ServiceResult.badResult(null);
        }
    }

    @Override
    public ServiceResult NotAttention(List idList) {
        try {
            if(idList!=null){
                cgoAdminAttentionDao.deleteById(idList);
                return ServiceResult.success();
            }else{
                return ServiceResult.badResult(null);
            }
        }catch (RuntimeException e){
            return ServiceResult.badResult(null);
        }
    }

    @Override
    public ServiceResult ClearHistory(Integer userId) {
        try {
            if(userId!=null){
                cgoAdminHistoryDao.deleteAllByUserId(userId);
                return ServiceResult.success();
            }else{
                return ServiceResult.badResult(null);
            }
        }catch (RuntimeException e){
            return ServiceResult.badResult(null);
        }
    }


}
